<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="ujn" uri="http://ujn.edu.cn/common/"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() 
	                   + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML> 
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title >购物车-用户管理</title>
	<!-- 引入css样式文件 -->
	<!-- Bootstrap Core CSS -->
	<link href="<%=basePath%>css/bootstrap.min.css" rel="stylesheet" />
	<!-- MetisMenu CSS -->
	<link href="<%=basePath%>css/metisMenu.min.css" rel="stylesheet" />
	<!-- DataTables CSS -->
	<link href="<%=basePath%>css/dataTables.bootstrap.css" rel="stylesheet" />
	<!-- Custom CSS -->
	<link href="<%=basePath%>css/sb-admin-2.css" rel="stylesheet" />
	<!-- Custom Fonts -->
	<link href="<%=basePath%>css/font-awesome.min.css" rel="stylesheet" type="text/css" />
	<link href="<%=basePath%>css/boot-crm.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
  <!-- 导航栏部分 -->
  <nav class="navbar navbar-default navbar-static-top" role="navigation"
		 style="margin-bottom: 0">
	<div class="navbar-header">
		<a class="navbar-brand" href="<%=basePath%>cartDetail/list.action">购物车详情管理系统</a>
	</div>
	
	<!-- 左侧显示列表部分 start-->
	<div class="navbar-default sidebar" role="navigation">
		<div class="sidebar-nav navbar-collapse">
			<ul class="nav" id="side-menu">
				<li class="sidebar-search">
					<div class="input-group custom-search-form">
						<input type="text" class="form-control" placeholder="查询内容...">
						<span class="input-group-btn">
							<button class="btn btn-default" type="button">
								<i class="fa fa-search" style="padding: 3px 0 3px 0;"></i>
							</button>
						</span>
					</div> 
				</li>
				<li>
				    <a href="${pageContext.request.contextPath }/cartDetail/list.action" class="active">
				      <i class="fa fa-edit fa-fw"></i> 购物车详情管理
				    </a>
				</li>
			</ul>
		</div>
	</div>
	<!-- 左侧显示列表部分 end--> 
  </nav>
    <!-- 客户列表查询部分  start-->
	<div id="page-wrapper">
		<div class="row">
			<div class="col-lg-12">
				<h1 class="page-header">购物车详情查询</h1>
			</div>
			<!-- /.col-lg-12 -->
		</div>
		<!-- /.row -->
		<a href="#" class="btn btn-primary" data-toggle="modal" 
		           data-target="#newCustomerDialog" onclick="clearCustomer()">新建</a>
		<div class="row">
			<div class="col-lg-12">
				<div class="panel panel-default">
					<div class="panel-heading">购物车详情信息列表</div>
					<!-- /.panel-heading -->
					<table class="table table-bordered table-striped">
						<thead>
							<tr>
								<th>购物车详情ID</th>
								<th>购物车ID</th>
								<th>书籍ID</th>
								<th>数量</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach items="${page.rows}" var="row">
								<tr>
									<td>${row.cartdetailid}</td>
									<td>${row.cartid}</td>
									<td>${row.bookid}</td>
									<td>${row.quantity}</td>
									<td>
										<a href="#" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#customerEditDialog" onclick= "editCustomer(${row.cartdetailid})">修改</a>
										<a href="#" class="btn btn-danger btn-xs" onclick="deleteCartDetail(${row.cartdetailid})">删除</a>
									</td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
					<div class="col-md-12 text-right">
						<ujn:page url="${pageContext.request.contextPath }/cartDetail/list.action" />
					</div>
					<!-- /.panel-body -->
				</div>
				<!-- /.panel -->
			</div>
			<!-- /.col-lg-12 -->
		</div>
	</div>
	<!-- 客户列表查询部分  end-->
</div>
<!-- 创建客户模态框 -->
<div class="modal fade" id="newCustomerDialog" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">新建信息</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" id="new_customer_form">
					<div class="form-group">
						<label for="new_cartdetailid" class="col-sm-2 control-label">
						    购物车详情ID
						</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_cartdetailid" placeholder="用户ID" name="cartdetailid" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_cartid" class="col-sm-2 control-label">
						    购物车ID
						</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_cartid" placeholder="购物车ID" name="cartid" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_bookid" class="col-sm-2 control-label">
						    书籍ID
						</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_bookid" placeholder="购物车ID" name="bookid" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_quantity" class="col-sm-2 control-label">
						    数量
						</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_quantity" placeholder="购物车ID" name="quantity" />
						</div>
					</div>
					<div class="form-group">
						<div class="col-sm-10">
							<input type="hidden" class="form-control" id="new_cartdetail_isdeleted" placeholder="购物车ID" name="isdeleted" value="0" />
						</div>
					</div>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" onclick="createCartDetail()">创建购物车</button>
			</div>
		</div>
	</div>
</div>
<!-- 修改客户模态框 -->
<div class="modal fade" id="customerEditDialog" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">修改购物车详情信息</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" id="edit_cartdetail_form">
					<div class="form-group">
						<label for="edit_cartdetailid" class="col-sm-2 control-label">购物车详情ID</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_cartdetailid" placeholder="购物车详情ID" name="cartdetailid" readonly="readonly"/>
						</div>
					</div>
					<div class="form-group">
						<label for="edit_cartid" class="col-sm-2 control-label">购物车ID</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_cartid" placeholder="购物车ID" name="cartid" />
						</div>
					</div>
					<div class="form-group">
						<label for="edit_bookid" class="col-sm-2 control-label">书籍ID</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_bookid" placeholder="书籍ID" name="bookid" />
						</div>
					</div>
					<div class="form-group">
						<label for="edit_quantity" class="col-sm-2 control-label">购买数量</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_quantity" placeholder="购买数量" name="quantity" />
						</div>
					</div>
					<div class="form-group">
						<div class="col-sm-10">
							<input type="hidden" id="edit_cartdetail_isdeleted" name="isdeleted" value="0"/>
						</div>
					</div>
					
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" onclick="updateCartDetail()">保存修改</button>
			</div>
		</div>
	</div>
</div>
<!-- 引入js文件 -->
<!-- jQuery -->
<script src="<%=basePath%>js/jquery-1.11.3.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="<%=basePath%>js/bootstrap.min.js"></script>
<!-- Metis Menu Plugin JavaScript -->
<script src="<%=basePath%>js/metisMenu.min.js"></script>
<!-- DataTables JavaScript -->
<script src="<%=basePath%>js/jquery.dataTables.min.js"></script>
<script src="<%=basePath%>js/dataTables.bootstrap.min.js"></script>
<!-- Custom Theme JavaScript -->
<script src="<%=basePath%>js/sb-admin-2.js"></script>
<!-- 编写js代码 -->
<script type="text/javascript">
//清空新建客户窗口中的数据
	function clearCustomer() {
	    $("#new_cartdetailid").val("");
	    $("#new_cartid").val("")
	    $("#new_bookid").val("")
	    $("#new_quantity").val("")
	    $("#new_cartdetail_isdeleted").val("")

	}
	// 创建客户
	function createCartDetail() {
	$.post("<%=basePath%>createCartDetail/create.action",
	$("#new_customer_form").serialize(),function(data){
	        if(data =="OK"){
	            alert("购物车详情创建成功！");
	            window.location.reload();
	        }else{
	            alert("购物车详情创建失败！");
	            window.location.reload();
	        }
	    });
	}
	// 通过id获取修改的客户信息
	function editCustomer(id) {
	    $.ajax({
	        type:"get",
	        url:"<%=basePath%>cartDetail/getCartDetailById.action",
	        data:{"id":id},
	        success:function(data) {
	            $("#edit_cartdetailid").val(data.cartdetailid);
	            $("#edit_cartid").val(data.cartid);
	            $("#edit_bookid").val(data.bookid);
	            $("#edit_quantity").val(data.quantity);
	            $("#edit_cartdetail_isdeleted").val(data.isdeleted);
	        }
	        
	    });
	}
    // 执行修改客户操作
	function updateCartDetail() {
		$.post("<%=basePath%>cartDetail/update.action",$("#edit_cartdetail_form").serialize(),function(data){
			if(data =="OK"){
				alert("购物车详情更新成功！");
				window.location.reload();
			}else{
				alert("购物车详情更新失败！");
				window.location.reload();
			}
		});
	}
	// 删除客户
	function deleteCartDetail(id) {
	    if(confirm('确实要删除该购物车详情吗?')) {
	$.post("<%=basePath%>cartDetail/delete.action",{"id":id},
	function(data){
	            if(data == "OK"){
	                alert("购物车详情删除成功！");
	                window.location.reload();
	            }else{
	                alert("删除购物车详情失败！");
	                window.location.reload();
	            }
	        });
	    }
	}
</script>
</body>
</html>